// pages/index/abc/index.js
import {list as wxPageList} from '../../../../api/wxPage'
import {list as navigationList} from '../../../../api/navigation'
const util = require('../../../../utils/util.js')
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
			info:{
				type:Object
			}
  },
		lifetimes:{
			attached(){
				let _this = this
        if (this.data.info.tagids != null) {
					this.data.tagIds = this.data.info.tagids.split(',')
					for (var i = 0; i < this.data.tagIds.length; i++) {
						this.data.tagIds[i] = parseInt(this.data.tagIds[i])
					}
				}
          this.setData({
            tagIds:this.data.tagIds
          })
				
				this.loadNavigation()
				this.loadPage((data)=>{
					console.info("wx.getImageInfo**************************")
					console.info(data)
					console.info("app.globalData.rpxR")
					console.info(app.globalData.rpxR)
					wx.getImageInfo({
					  src: data[0].thumbnial,
					  success: function (res) {
						console.info("wx.getImageInfo**************************")
						console.info(res)
						_this.setData({
							imageHeight:res.height
						})
					  }
					})
				})
      }
				
		},
  /**
   * 组件的初始数据
   */
  data: {
		tagIds:[],
		pageSize:4,
		pageList:[],
		navigations:[],
		imageHeight:"",
	welfareList: [
		{
			text: '家居用品',
			img: ''
		},
		{
			text: '数码家电',
			img: ''
		},
		{
			text: '洗护用品',
			img: ''
		},
		{
			text: '中秋美食',
			img: ''
		},
	]
  },
  created(){

  },
  /**
   * 组件的方法列表
   */
  methods: {
		toItem(e){
			console.info("跳转活动页-------------------")
			console.info(e.currentTarget.dataset.id)
			wx.navigateTo({
				url: '/pages/index/wxPage/wxPage?id='+e.currentTarget.dataset.id
		})
		},
		loadNavigation(){
			navigationList({
				tagIds:this.data.tagIds,
				pageSize:this.data.pageSize,
				mchId:app.globalData.mchId
			}).then(res=>{
				this.data.navigations=res.data.data
				this.setData({
					navigations:this.data.navigations
				})
			})
		},
		loadPage(callback){
			var _this = this;
      wxPageList({
				mchId:app.globalData.mchId,
				tagIds:_this.data.tagIds,
			}).then(res=>{
				console.info("xcxAd000000000000000000000000000000000000000000000000000000000000")
				console.info(res)
				_this.data.pageList=res.data.data
				// _this.data.pageList[0].thumbnial = util.thumbnail(_this.data.pageList[0].thumbnial,710,355)
				_this.setData({
            	pageList:_this.data.pageList
		  	})
		  if(callback){
			  callback(_this.data.pageList)
		  }
      })
    },
	itemClick (data) {
		console.log(data)

		if (data.currentTarget.dataset.index.type == 3) {
			wx.navigateTo({
			  url: '/pages/shop/productDetail/productDetail?productId=' + data.currentTarget.dataset.index.typeId
			})
		  } 
		//   else if (data.currentTarget.dataset.index.type == 2) {
		// 	wx.navigateTo({
		// 	  url: '/pages/hotspot/hotspot/index?id=' + data.currentTarget.dataset.index.id,
		// 	})
		//   } else if (data.currentTarget.dataset.index.type == 3) {
		// 	wx.navigateTo({
		// 	  url: '/pages/discovery/details/details?id=' + data.currentTarget.dataset.index.id
		// 	})
		//   } else if (data.currentTarget.dataset.index.type == 4) {
		// 	wx.navigateTo({
		// 	  url: '/pages/travel/travel/index?scenicSpotId=' + data.currentTarget.dataset.index.id
		// 	})
		//   } 
		else if (data.currentTarget.dataset.index.type == 4) {
			wx.navigateTo({
			  url: '/pages/shop/shopDetail/index?shopId=' + data.currentTarget.dataset.index.typeId + '&mchId=' + app.globalData.mchId
			})
		  } 
		// else if (data.currentTarget.dataset.index.type == 6) {
		// 	wx.navigateTo({
		// 	  url: '/pages/cook/kitchenBrigade/kitchenBrigade?id=' + data.currentTarget.dataset.index.id + '&mchId=' + app.globalData.index.mchId
		// 	})
		//   } else if (data.currentTarget.dataset.index.type == 7) {
		// 	wx.navigateTo({
		// 	  url: '/pages/shop/shopDetail/index?shopId=' + data.currentTarget.dataset.index.id + '&mchId=' + app.globalData.index.mchId
		// 	})
		//   } else if (data.currentTarget.dataset.index.type == 8) {
		// 	wx.navigateTo({
		// 	  url: '/pages/coupon/coupon',
		// 	})
		//   } else if (data.currentTarget.dataset.index.type == 9) {
		// 	wx.navigateTo({
		// 	  url: '/pages/index/wxPage/wxPage?id='+data.currentTarget.dataset.index.id 
		// 	})
		//   }
		//   else if (data.currentTarget.dataset.index.type == 12) {
		// 	wx.navigateTo({
		// 	  url: '/pages/member/webview/index?url='+data.currentTarget.dataset.index.typeName
		// 	})
		//   }
	}
  }
})
